<!DOCTYPE html>
<html lang="en">
  <head>
    <title>NetTCP Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
  </head>
  <body>
    <a name="//apple_ref/swift/Class/NetTCP" class="dashAnchor"></a>
    <a title="NetTCP Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../index.html"> Docs</a> (83% documented)</p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../index.html"> Reference</a>
        <img id="carat" src="../img/carat.png" />
        NetTCP Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
          <a href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Classes/AJAXObjectDriver.html">AJAXObjectDriver</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Bytes.html">Bytes</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CURL.html">CURL</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes.html#/s:C10PerfectLib6Cookie">Cookie</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Dir.html">Dir</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Encoding.html">Encoding</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/FastCGIServer.html">FastCGIServer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/File.html">File</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/HTTPServer.html">HTTPServer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ICU.html">ICU</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/JSONArrayType.html">JSONArrayType</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/JSONDecode.html">JSONDecode</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/JSONDictionaryType.html">JSONDictionaryType</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/JSONEncode.html">JSONEncode</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/JSONNull.html">JSONNull</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes.html#/s:C10PerfectLib10LogManager">LogManager</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MimeReader.html">MimeReader</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheEvaluationContext.html">MoustacheEvaluationContext</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheEvaluationOutputCollector.html">MoustacheEvaluationOutputCollector</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheGroupTag.html">MoustacheGroupTag</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheParser.html">MoustacheParser</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustachePartialTag.html">MoustachePartialTag</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustachePragmaTag.html">MoustachePragmaTag</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheTag.html">MoustacheTag</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MoustacheTemplate.html">MoustacheTemplate</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/NetNamedPipe.html">NetNamedPipe</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/NetTCP.html">NetTCP</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/NetTCPSSL.html">NetTCPSSL</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PageHandlerRegistry.html">PageHandlerRegistry</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PerfectObject.html">PerfectObject</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PerfectObjectHandler.html">PerfectObjectHandler</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PerfectServer.html">PerfectServer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/SQLite.html">SQLite</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/SQLiteStmt.html">SQLiteStmt</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/SessionManager.html">SessionManager</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/SysProcess.html">SysProcess</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/UTF16Encoding.html">UTF16Encoding</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/UTF8Encoding.html">UTF8Encoding</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/WebRequest.html">WebRequest</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/WebResponse.html">WebResponse</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Global Variables.html">Global Variables</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Global Variables.html#/s:v10PerfectLib17PERFECT_LIBRARIESSS">PERFECT_LIBRARIES</a>
              </li>
              <li class="nav-group-task">
                <a href="../Global Variables.html#/s:v10PerfectLib10SQLITE_DBSSS">SQLITE_DBS</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Enums.html">Enums</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Enums/HandlerAction.html">HandlerAction</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/JSONError.html">JSONError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/MoustacheError.html">MoustacheError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/PerfectError.html">PerfectError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/SQLiteError.html">SQLiteError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/SessionResult.html">SessionResult</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Extensions/Closeable.html">Closeable</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/HandlerAction.html">HandlerAction</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/PerfectObjectDriver.html">PerfectObjectDriver</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/String.html">String</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/UnicodeScalar.html">UnicodeScalar</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Functions.html">Functions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Functions.html#/s:F10PerfectLib10FileStderrFT_CS_4File">FileStderr()</a>
              </li>
              <li class="nav-group-task">
                <a href="../Functions.html#/s:F10PerfectLib9FileStdinFT_CS_4File">FileStdin()</a>
              </li>
              <li class="nav-group-task">
                <a href="../Functions.html#/s:F10PerfectLib10FileStdoutFT_CS_4File">FileStdout()</a>
              </li>
              <li class="nav-group-task">
                <a href="../Functions.html#/s:F10PerfectLib10empty_uuidFT_TVSs5UInt8S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0__">empty_uuid()</a>
              </li>
              <li class="nav-group-task">
                <a href="../Functions.html#/s:F10PerfectLib11random_uuidFT_TVSs5UInt8S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0_S0__">random_uuid()</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Protocols/Closeable.html">Closeable</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/PageHandler.html">PageHandler</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/PerfectObjectDriver.html">PerfectObjectDriver</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/WebConnection.html">WebConnection</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
          <a href="../Structs.html">Structs</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Structs/GenerateFromPointer.html">GenerateFromPointer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/SessionConfiguration.html">SessionConfiguration</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs.html#/s:V10PerfectLib20SocketFileDescriptor">SocketFileDescriptor</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>NetTCP</h1>
              <div class="declaration">
                <div class="Swift">
                  <pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">NetTCP</span> <span class="p">:</span> <span class="kt">Closeable</span></code></pre>

                </div>
              </div>
            <p>Provides an asynchronous IO wrapper around a file descriptor.
Fully realized for TCP socket types but can also serve as a base for sockets from other families, such as with <code>NetNamedPipe</code>/AF_UNIX.</p>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCPcFMS0_FT_S0_"></a>
                    <a name="//apple_ref/swift/Method/init()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCPcFMS0_FT_S0_">init()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Create a new object with an initially invalid socket file descriptor.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCPcFMS0_FT2fdVSs5Int32_S0_"></a>
                    <a name="//apple_ref/swift/Method/init(fd:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCPcFMS0_FT2fdVSs5Int32_S0_">init(fd:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Creates an instance which will use the given file descriptor
- parameter fd: The pre-existing file descriptor</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="n">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">fd</span><span class="p">:</span> <span class="kt">Int32</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>fd</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The pre-existing file descriptor</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP10initSocketFS0_FT_T_"></a>
                    <a name="//apple_ref/swift/Method/initSocket()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP10initSocketFS0_FT_T_">initSocket()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Allocates a new socket if it has not already been done.
The functions <code>bind</code> and <code>connect</code> will call this method to ensure the socket has been allocated.
Sub-classes should override this function in order to create their specialized socket.
All sub-class sockets should be switched to utilize non-blocking IO by calling <code>SocketFileDescriptor.switchToNBIO()</code>.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">initSocket</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP4bindFS0_FzTVSs6UInt167addressSS_T_"></a>
                    <a name="//apple_ref/swift/Method/bind(_:address:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP4bindFS0_FzTVSs6UInt167addressSS_T_">bind(_:address:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Bind the socket on the given port and optional local address
- parameter port: The port on which to bind
- parameter address: The the local address, given as a string, on which to bind. Defaults to <q>0.0.0.0</q>.
- throws: PerfectError.NetworkError</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">bind</span><span class="p">(</span><span class="nv">port</span><span class="p">:</span> <span class="kt">UInt16</span><span class="p">,</span> <span class="nv">address</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"0.0.0.0"</span><span class="p">)</span> <span class="n">throws</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>port</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The port on which to bind</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>address</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The the local address, given as a string, on which to bind. Defaults to <q>0.0.0.0</q>.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP6listenFS0_FTVSs5Int32_T_"></a>
                    <a name="//apple_ref/swift/Method/listen(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP6listenFS0_FTVSs5Int32_T_">listen(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Switches the socket to server mode. Socket should have been previously bound using the <code>bind</code> function.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">listen</span><span class="p">(</span><span class="nv">backlog</span><span class="p">:</span> <span class="kt">Int32</span> <span class="o">=</span> <span class="mi">128</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP5closeFS0_FT_T_"></a>
                    <a name="//apple_ref/swift/Method/close()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP5closeFS0_FT_T_">close()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Shuts down and closes the socket.
The object may be reused.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">close</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP14readBytesFullyFS0_FTSi14timeoutSecondsSd10completionFGSqGSaVSs5UInt8__T__T_"></a>
                    <a name="//apple_ref/swift/Method/readBytesFully(_:timeoutSeconds:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP14readBytesFullyFS0_FTSi14timeoutSecondsSd10completionFGSqGSaVSs5UInt8__T__T_">readBytesFully(_:timeoutSeconds:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Read the indicated number of bytes and deliver them on the provided callback.
- parameter count: The number of bytes to read
- parameter timeoutSeconds: The number of seconds to wait for the requested number of bytes. A timeout value of negative one indicates that the request should have no timeout.
- parameter completion: The callback on which the results will be delivered. If the timeout occurs before the requested number of bytes have been read, a nil object will be delivered to the callback.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">readBytesFully</span><span class="p">(</span><span class="nv">count</span><span class="p">:</span> <span class="kt">Int</span><span class="p">,</span> <span class="nv">timeoutSeconds</span><span class="p">:</span> <span class="kt">Double</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">([</span><span class="kt">UInt8</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>count</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The number of bytes to read</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>timeoutSeconds</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The number of seconds to wait for the requested number of bytes. A timeout value of negative one indicates that the request should have no timeout.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback on which the results will be delivered. If the timeout occurs before the requested number of bytes have been read, a nil object will be delivered to the callback.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP13readSomeBytesFS0_FTSi10completionFGSqGSaVSs5UInt8__T__T_"></a>
                    <a name="//apple_ref/swift/Method/readSomeBytes(_:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP13readSomeBytesFS0_FTSi10completionFGSqGSaVSs5UInt8__T__T_">readSomeBytes(_:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Read up to the indicated number of bytes and deliver them on the provided callback.
- parameter count: The maximum number of bytes to read.
- parameter completion: The callback on which to deliver the results. If an error occurs during the read then a nil object will be passed to the callback, otherwise, the immediately available number of bytes, which may be zero, will be passed.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">readSomeBytes</span><span class="p">(</span><span class="nv">count</span><span class="p">:</span> <span class="kt">Int</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">([</span><span class="kt">UInt8</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>count</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The maximum number of bytes to read.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback on which to deliver the results. If an error occurs during the read then a nil object will be passed to the callback, otherwise, the immediately available number of bytes, which may be zero, will be passed.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP5writeFS0_FTSS10completionFSiT__T_"></a>
                    <a name="//apple_ref/swift/Method/write(_:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP5writeFS0_FTSS10completionFSiT__T_">write(_:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the string and call the callback with the number of bytes which were written.
- parameter s: The string to write. The string will be written based on its UTF-8 encoding.
- parameter completion: The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">write</span><span class="p">(</span><span class="nv">s</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>s</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The string to write. The string will be written based on its UTF-8 encoding.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP5writeFS0_FTGSaVSs5UInt8_10completionFSiT__T_"></a>
                    <a name="//apple_ref/swift/Method/write(_:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP5writeFS0_FTGSaVSs5UInt8_10completionFSiT__T_">write(_:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the indicated bytes and call the callback with the number of bytes which were written.
- parameter bytes: The array of UInt8 to write.
- parameter completion: The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">write</span><span class="p">(</span><span class="nv">bytes</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">],</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>bytes</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The array of UInt8 to write.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP11writeStringFS0_FTSS10completionFSiT__T_"></a>
                    <a name="//apple_ref/swift/Method/writeString(_:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP11writeStringFS0_FTSS10completionFSiT__T_">writeString(_:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the string and call the callback with the number of bytes which were written.
- parameter s: The string to write. The string will be written based on its UTF-8 encoding.
- parameter completion: The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">writeString</span><span class="p">(</span><span class="nv">s</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>s</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The string to write. The string will be written based on its UTF-8 encoding.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP10writeBytesFS0_FTGSaVSs5UInt8_10completionFSiT__T_"></a>
                    <a name="//apple_ref/swift/Method/writeBytes(_:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP10writeBytesFS0_FTGSaVSs5UInt8_10completionFSiT__T_">writeBytes(_:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the indicated bytes and call the callback with the number of bytes which were written.
- parameter bytes: The array of UInt8 to write.
- parameter completion: The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">writeBytes</span><span class="p">(</span><span class="nv">bytes</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">],</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>bytes</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The array of UInt8 to write.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP15writeBytesFullyFS0_FGSaVSs5UInt8_Sb"></a>
                    <a name="//apple_ref/swift/Method/writeBytesFully(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP15writeBytesFullyFS0_FGSaVSs5UInt8_Sb">writeBytesFully(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the indicated bytes and return true if all data was sent.
- parameter bytes: The array of UInt8 to write.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">writeBytesFully</span><span class="p">(</span><span class="nv">bytes</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>bytes</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The array of UInt8 to write.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP10writeBytesFS0_FTGSaVSs5UInt8_12dataPositionSi6lengthSi10completionFSiT__T_"></a>
                    <a name="//apple_ref/swift/Method/writeBytes(_:dataPosition:length:completion:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP10writeBytesFS0_FTGSaVSs5UInt8_12dataPositionSi6lengthSi10completionFSiT__T_">writeBytes(_:dataPosition:length:completion:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Write the indicated bytes and call the callback with the number of bytes which were written.
- parameter bytes: The array of UInt8 to write.
- parameter dataPosition: The offset within <code>bytes</code> at which to begin writing.
- parameter length: The number of bytes to write.
- parameter completion: The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">writeBytes</span><span class="p">(</span><span class="nv">bytes</span><span class="p">:</span> <span class="p">[</span><span class="kt">UInt8</span><span class="p">],</span> <span class="nv">dataPosition</span><span class="p">:</span> <span class="kt">Int</span><span class="p">,</span> <span class="nv">length</span><span class="p">:</span> <span class="kt">Int</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="p">(</span><span class="kt">Int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>bytes</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The array of UInt8 to write.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>dataPosition</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The offset within <code>bytes</code> at which to begin writing.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>length</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The number of bytes to write.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>completion</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback which will be called once the write has completed. The callback will be passed the number of bytes which were successfuly written, which may be zero.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP7connectFS0_FzTSS4portVSs6UInt1614timeoutSecondsSd8callBackFGSqS0__T__T_"></a>
                    <a name="//apple_ref/swift/Method/connect(_:port:timeoutSeconds:callBack:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP7connectFS0_FzTSS4portVSs6UInt1614timeoutSecondsSd8callBackFGSqS0__T__T_">connect(_:port:timeoutSeconds:callBack:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Connect to the indicated server
- parameter address: The server&rsquo;s address, expressed as a string.
- parameter port: The port on which to connect.
- parameter timeoutSeconds: The number of seconds to wait for the connection to complete. A timeout of negative one indicates that there is no timeout.
- parameter callBack: The closure which will be called when the connection completes. If the connection completes successfully then the current NetTCP instance will be passed to the callback, otherwise, a nil object will be passed.
- returns: <code>PerfectError.NetworkError</code></p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">connect</span><span class="p">(</span><span class="nv">address</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">port</span><span class="p">:</span> <span class="kt">UInt16</span><span class="p">,</span> <span class="nv">timeoutSeconds</span><span class="p">:</span> <span class="kt">Double</span><span class="p">,</span> <span class="nv">callBack</span><span class="p">:</span> <span class="p">(</span><span class="kt">NetTCP</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="p">())</span> <span class="n">throws</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>address</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The server&rsquo;s address, expressed as a string.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>port</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The port on which to connect.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>timeoutSeconds</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The number of seconds to wait for the connection to complete. A timeout of negative one indicates that there is no timeout.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>callBack</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The closure which will be called when the connection completes. If the connection completes successfully then the current NetTCP instance will be passed to the callback, otherwise, a nil object will be passed.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p><code>PerfectError.NetworkError</code></p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP6acceptFS0_FzTSd8callBackFGSqS0__T__T_"></a>
                    <a name="//apple_ref/swift/Method/accept(_:callBack:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP6acceptFS0_FzTSd8callBackFGSqS0__T__T_">accept(_:callBack:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Accept a new client connection and pass the result to the callback.
- parameter timeoutSeconds: The number of seconds to wait for a new connection to arrive. A timeout value of negative one indicates that there is no timeout.
- parameter callBack: The closure which will be called when the accept completes. the parameter will be a newly allocated instance of NetTCP which represents the client.
- returns: <code>PerfectError.NetworkError</code></p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">accept</span><span class="p">(</span><span class="nv">timeoutSeconds</span><span class="p">:</span> <span class="kt">Double</span><span class="p">,</span> <span class="nv">callBack</span><span class="p">:</span> <span class="p">(</span><span class="kt">NetTCP</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="p">())</span> <span class="n">throws</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>timeoutSeconds</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The number of seconds to wait for a new connection to arrive. A timeout value of negative one indicates that there is no timeout.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>callBack</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The closure which will be called when the accept completes. the parameter will be a newly allocated instance of NetTCP which represents the client.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p><code>PerfectError.NetworkError</code></p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC10PerfectLib6NetTCP13forEachAcceptFS0_FFGSqS0__T_T_"></a>
                    <a name="//apple_ref/swift/Method/forEachAccept(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC10PerfectLib6NetTCP13forEachAcceptFS0_FFGSqS0__T_T_">forEachAccept(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Accept a series of new client connections and pass them to the callback. This function does not return outside of a catastrophic error.
- parameter callBack: The closure which will be called when the accept completes. the parameter will be a newly allocated instance of NetTCP which represents the client.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="Swift">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">forEachAccept</span><span class="p">(</span><span class="nv">callBack</span><span class="p">:</span> <span class="p">(</span><span class="kt">NetTCP</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="p">())</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callBack</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The closure which will be called when the accept completes. the parameter will be a newly allocated instance of NetTCP which represents the client.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2015 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2015-11-04)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.3.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
